package com.example.designpatterns.composite;

// 叶子组件：表示树形结构中的叶子节点
public class Leaf extends Component {
    public Leaf(String name) {
        super(name);
    }

    @Override
    public void display(int depth) {
        // 兼容 Java 8 及以上版本的写法
        StringBuilder dashes = new StringBuilder();
        for (int i = 0; i < depth; i++) {
            dashes.append("-");
        }
        System.out.println(dashes.toString() + name);
    }
}